<template>
    <div id="form">
        <el-form ref="form" :model="fundData" label-width="150px">
            <el-form-item label="基金名称">
                <el-input
                    v-model="fundData.fundName"
                    style="width: 300px"
                ></el-input>
            </el-form-item>
            <el-form-item label="基金类型">
                <el-select
                    v-model="fundData.fundType"
                    placeholder="请选择基金类型"
                >
                    <el-option
                        :label="item.text1"
                        :value="item.text2"
                        v-for="item in type"
                        :key="item.text1"
                    >
                        <span style="float: left">{{ item.text1 }}</span>
                        <span
                            style="
                                float: right;
                                color: #8492a6;
                                font-size: 13px;
                            "
                            >{{ item.text2 }}</span
                        >
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="基金名称缩写">
                <el-input
                    v-model="fundData.fundNameAbbr"
                    style="width: 300px"
                ></el-input>
            </el-form-item>
            <el-form-item label="基金公司名称">
                <el-input
                    v-model="fundData.fundCompanyName"
                    style="width: 300px"
                ></el-input>
            </el-form-item>

            <el-form-item label="基金策略">
                <el-input
                    type="textarea"
                    v-model="fundData.investStrategy"
                ></el-input>
            </el-form-item>
            <el-form-item label="基金理念">
                <el-input
                    type="textarea"
                    v-model="fundData.investPhilosophy"
                ></el-input>
            </el-form-item>
            <el-form-item label="风险等级">
                <el-select
                    v-model="fundData.riskLevel"
                    placeholder="请选择风险等级"
                >
                    <el-option
                        v-for="item in riskData"
                        :key="item.userMinLevel"
                        :label="item.gdescription"
                        :value="item.grade"
                    >
                        <span style="float: left">{{ item.gdescription }}</span>
                        <span
                            style="
                                float: right;
                                color: #8492a6;
                                font-size: 13px;
                            "
                            >{{ item.grade }}</span
                        >
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="购买状态">
                <el-select
                    v-model="fundData.saleStatus"
                    placeholder="请选择购买状态"
                >
                    <el-option
                        :label="item.text2"
                        :value="item.text2"
                        v-for="item in status"
                        :key="item.text1"
                    >
                        <span style="float: left">{{ item.text1 }}</span>
                        <span
                            style="
                                float: right;
                                color: #8492a6;
                                font-size: 13px;
                            "
                            >{{ item.text2 }}</span
                        >
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="赎回基础费率">
                <el-input
                    v-model="fundData.sellRate"
                    style="width: 200px"
                ></el-input>
            </el-form-item>
            <el-form-item label="管理费率">
                <el-input
                    v-model="fundData.trusteeRate"
                    style="width: 200px"
                ></el-input>
            </el-form-item>
            <el-form-item label="买入费率">
                <el-input
                    v-model="fundData.manageRate"
                    style="width: 200px"
                ></el-input>
            </el-form-item>
            <el-form-item label="投资策略">
                <el-select
                    v-model="fundData.policy"
                    placeholder="请选择投资策略"
                >
                    <el-option
                        :label="item.investorType"
                        :value="item.investorType"
                        v-for="item in riskData"
                        :key="item.userMinLevel"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">保存</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
export default {
    props: ["id"],
    data() {
        return {
            fundData: {},
            riskData: [],
            type: [
                { text1: "混合型", text2: "BLEND" },
                { text1: "股票型", text2: "STOCK" },
                { text1: "指数型", text2: "INDEX" },
                { text1: "债券型", text2: "BOND" },
                { text1: "货币型", text2: "CURRENCY" },
            ],
            status: [
                { text1: "认购期", text2: "SUBSCRIBE" },
                { text1: "开放买卖", text2: "PURCHASE" },
                { text1: "本平台暂不销售", text2: "OFF" },
            ],
        };
    },
    created() {
        this.getrisk();
    },
    methods: {
        //提交
        async onSubmit() {
            const res = await this.api.fund.addone({
                ...this.fundData,
            });
            console.log(res)
            if (res.code == 200) {
                this.$message({
                    showClose: true,
                    message: "添加成功",
                    type: "success",
                });
            } else {
                this.$message({
                    showClose: true,
                    message: "添加失败",
                    type: "error",
                });
            }
        },
        //获取风险等级和投资策略
        async getrisk() {
            const res = await this.api.fund.getrisk();
            if (res.code == 200) {
                this.riskData = res.data;
            }
        },
    },
};
</script>

<style scoped>
#form {
    text-align: left;
}
</style>